<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
		<script src="../jquery-1.7.2.min.js"></script>
		<script>
			$(function(){
				
				
//				代码复用核心思想是:每个框都有一套自己的大总管/自己的定时器／自己的run方法
				$('.box').each(function(){
					var $this = $(this);
					var This = $(this).get(0);//为什么要得到js原生的对象呢？因为js原生的对象可以挂载自定义的属性和方法
					This.i = 0;
					This.run = function(){
						This.i++;
						if(This.i>5){
							This.i=1;
							$this.find('ul').css('top',0);
						}
						$this.find('ul').animate({top:-40*This.i},300);
					}
					This.timer = setInterval(This.run,1000);
				})
				$('.box').hover(function(){
					var This = $(this).get(0);
					clearInterval(This.timer);
				},function(){
					var This = $(this).get(0);
					This.timer = setInterval(This.run,1000);
				})
			})
		</script>
		<style>
			*{
				padding:0;
				margin:0;
				list-style: none;
			}
			.box{
				width:500px;
				height:40px;
				line-height: 40px;
				border:5px solid red;
				margin:50px auto;
				position:relative;
				overflow: hidden;
			}
			.box ul {
				width:500px;
				border:1px solid black;
				position:absolute;
				top:0;
				left:0;
			}
			.box ul li{
				width:500px;
				height:40px;
				color:white;
				font-weight: 700;
			}
			.box ul li:nth-of-type(1){
				background: red;
			}
			.box ul li:nth-of-type(2){
				background: green;
			}
			.box ul li:nth-of-type(3){
				background: purple;
			}
			.box ul li:nth-of-type(4){
				background: orange;
			}
			.box ul li:nth-of-type(5){
				background: blue;
			}
			.box ul li:nth-of-type(6){
				background: red;
			}
		</style>
	</head>
	<body>
		<div class="box">
			<ul>
				<li>111</li>
				<li>222</li>
				<li>333</li>
				<li>444</li>
				<li>555</li>
				<li>111</li>
			</ul>
		</div>
		<div class="box">
			<ul>
				<li>111</li>
				<li>222</li>
				<li>333</li>
				<li>444</li>
				<li>555</li>
				<li>111</li>
			</ul>
		</div>
		<div class="box">
			<ul>
				<li>111</li>
				<li>222</li>
				<li>333</li>
				<li>444</li>
				<li>555</li>
				<li>111</li>
			</ul>
		</div>
	</body>
</html>
